package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleAuthDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleGetPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyHouseholdRoleSaveDTO;
import com.itlong.cloud.POJO.VO.property.PropertyHouseHoldRoleElevatorGetPageVO;
import com.itlong.cloud.POJO.VO.property.PropertyHouseholdRoleEntranceGetPageVO;
import com.itlong.cloud.POJO.VO.property.PropertyHouseholdRoleGetPageVO;
import com.itlong.cloud.property.service.IPropertyHouseholdRoleService;
import com.itlong.cloud.user.property.IPropertyHouseholdRoleServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业系统住户权限(角色组)分配接口服务暴露接口实现类
 * </desc>
 *
 * @createDate 2019/02/20
 */
@RestController
public class PropertyHouseholdRoleServiceResource implements IPropertyHouseholdRoleServiceClient {

    @Autowired
    private IPropertyHouseholdRoleService iPropertyHouseholdRoleService;

    /**
     * <desc>
     *      添加住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleSaveDTO 添加住户角色组信息数据DTO
     * @return 受影响的行数
     * @author wangzhi
     * @createDate 2019/02/20
     */
    @Override
    @PostMapping(path = "property/householdRole/saveHouseholdRole")
    public Map<String,String> saveHouseholdRole(@RequestBody PropertyHouseholdRoleSaveDTO propertyHouseholdRoleSaveDTO) throws Exception {
        return iPropertyHouseholdRoleService.saveHouseholdRole(propertyHouseholdRoleSaveDTO);
    }

    /**
     * <desc>
     *      分页获取住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 添加住户角色组信息数据DTO
     * @return 分页结果
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/getPage")
    public Page<PropertyHouseholdRoleGetPageVO> getPage(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.getPage(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      获取单个住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 添加住户角色组信息数据DTO
     * @return 单个住户角色组信息
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/getOne")
    public PropertyHouseholdRoleGetPageVO getOne(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.getOne(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      修改住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 1-成功，0-失败
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/update")
    public Integer update(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.update(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      校验住户角色组信息是否有关联数据
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 1-有，0-无
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/checkRoleData")
    public Integer checkRoleData(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception{
        return iPropertyHouseholdRoleService.checkRoleData(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      删除住户角色组信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 受影响行数
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/delete")
    public Integer delete(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.delete(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      分页获取门禁设备列表信息
     * </desc>
     *
     * @param propertyHouseholdRoleGetPageDTO 获取分页住户角色组信息DTO
     * @return 门禁设备列表信息
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/getEntrancePage")
    public Page<PropertyHouseholdRoleEntranceGetPageVO> getEntrancePage(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.getEntrancePage(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      获取角色绑定的用户id列表
     * </desc>
     *
     * @param roleId 角色id
     * @return 用户id列表
     * @author wangzhi
     * @createDate 2019/02/21
     */
    @Override
    @PostMapping(path = "property/householdRole/getUserIdListByRoleId")
    public List<String> getUserIdListByRoleId(@RequestParam("roleId") String roleId) throws Exception {
        return iPropertyHouseholdRoleService.getUserIdListByRoleId(roleId);
    }

    /**
     * <desc>
     *      获取角色绑定的用户id列表,有人脸的用户
     * </desc>
     *
     * @param roleId 角色id
     * @param projectId 项目id
     * @return 用户id列表
     * @author Qiang.S
     * @createDate 2020/03/16
     */
    @Override
    @PostMapping(path = "property/householdRole/getUserIdFaceListByRoleId")
    public List<String> getUserIdFaceListByRoleId(@RequestParam("roleId") String roleId, @RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.getUserIdFaceListByRoleId(roleId,projectId);
    }

    /**
     * <desc>
     *      获取角色绑定的设备序列号列表
     * </desc>
     *
     * @param roleId 角色id
     * @param type 1为查询启用状态 2为非删除状态
     * @return 用户id列表
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @Override
    @PostMapping(path = "property/householdRole/getDeviceUniqueListByRoleId")
    public List<String> getDeviceUniqueListByRoleId(@RequestParam("roleId") String roleId,@RequestParam("type") String type) throws Exception {
        return iPropertyHouseholdRoleService.getDeviceUniqueListByRoleId(roleId,type);
    }

    /**
     * <desc>
     *      获取用户在非指定分组的设备序列号列表
     * </desc>
     *
     * @param roleId 角色id
     * @param userId 用户id
     * @param projectId 项目id
     * @return 设备列表
     * @author Juguang.S
     * @createDate 2021/04/02
     */
    @Override
    @PostMapping(path = "property/householdRole/getEntranceListByNotInRoleIdAndUserId")
    public  List<String> getEntranceListByNotInRoleIdAndUserId(@RequestParam(value = "roleId",required = false) String roleId,
                                                               @RequestParam("userId") String userId,
                                                               @RequestParam("projectId") String projectId) throws Exception{
        return iPropertyHouseholdRoleService.getEntranceListByNotInRoleIdAndUserId(roleId,userId,projectId);
    }

    /**
     * <desc>
     *      获取角色绑定的电梯设备序列号列表
     * </desc>
     *
     * @param roleId 角色id
     * @param type 1为查询启用状态 2为非删除状态
     * @return 用户id列表
     * @author Juguang.S
     * @createDate 2021/04/01
     */
    @Override
    @PostMapping(path = "property/householdRole/getElevatorListByRoleId")
    public Map<String,Object> getElevatorListByRoleId(@RequestParam("roleId") String roleId,@RequestParam("type") String type) throws Exception {
        return iPropertyHouseholdRoleService.getElevatorListByRoleId(roleId,type);
    }

    /**
     * <desc>
     *      获取用户非指定分组外的电梯设备序列号列表
     * </desc>
     *
     * @param roleId 角色id
     * @param userId 用户id
     * @param projectId 项目id
     * @return 用户id列表
     * @author Juguang.S
     * @createDate 2021/04/02
     */
    @Override
    @PostMapping(path = "property/householdRole/getElevatorListByNotInRoleIdAndUserId")
    public Map<String,Object> getElevatorListByNotInRoleIdAndUserId(@RequestParam(value = "roleId",required = false) String roleId,
                                                                    @RequestParam(value = "userId") String userId,
                                                                    @RequestParam("projectId") String projectId)throws Exception{
        return iPropertyHouseholdRoleService.getElevatorListByNotInRoleIdAndUserId(roleId,userId,projectId);
    }

    /**
     * <desc>
     *      住户角色组信息设备授权
     * </desc>
     *
     * @return 0-失败 1-成功
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @Override
    @PostMapping(path = "property/householdRole/deviceAuth")
    public Integer deviceAuth(@RequestBody PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO) throws Exception {
        return iPropertyHouseholdRoleService.deviceAuth(propertyHouseholdRoleAuthDTO);
    }

    /**
     * <desc>
     *      住户角色组信息人员分配
     * </desc>
     *
     * @return 0-失败 1-成功
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @Override
    @PostMapping(path = "property/householdRole/userAuth")
    public Integer userAuth(@RequestBody PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO) throws Exception {
        return iPropertyHouseholdRoleService.userAuth(propertyHouseholdRoleAuthDTO);
    }

    /**
     * <desc>
     *      拿到当前角色id所有普通门禁设备序列号字符串
     * </desc>
     *
     * @return 所有普通门禁设备序列号字符串
     * @author wangzhi
     * @createDate 2019/02/22
     */
    @Override
    @PostMapping(path = "property/householdRole/getAllDeviceUniqueStr")
    public String getAllDeviceUniqueStr(@RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.getAllDeviceUniqueStr(projectId);
    }

    /**
     *<desc>
     *      根据项目编号查询所有的电梯设备
     *</desc>
     *
     * @return 所有的电梯设备序列号字符串
     * @author Juguang.S
     * @createDate 2021/04/01
     */
    @Override
    @PostMapping(path = "property/householdRole/getAllElevatorDeviceUniqueStr")
    public String getAllElevatorDeviceUniqueStr(@RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.getAllElevatorDeviceUniqueStr(projectId);
    }

    /**
     *<desc>
     *      过滤有人脸的用户
     *</desc>
     *
     * @param userIds 用户id
     * @param projectId 项目id
     * @return
     * @author Qiang.S
     * @createDate 2020/03/16
     */
    @Override
    @PostMapping(path = "property/householdRole/getUserHaveFace")
    public List<String> getUserHaveFace(@RequestBody List<String> userIds, @RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.getUserHaveFace(userIds,projectId);
    }


    /**
     * <desc>
     *      获取电梯分页列表
     * </desc>
     *
     * @param
     * @return 电梯分页列表
     * @Author Zhu.yj
     * @createDate  2021/3/29
     */
    @PostMapping(path = "property/householdRole/getElevatorPage")
    @Override
    public Page<PropertyHouseHoldRoleElevatorGetPageVO> getElevatorPage(@RequestBody PropertyHouseholdRoleGetPageDTO propertyHouseholdRoleGetPageDTO) throws Exception {
        return iPropertyHouseholdRoleService.getElevatorPage(propertyHouseholdRoleGetPageDTO);
    }

    /**
     * <desc>
     *      校验输入的用户分组是否合法
     * </desc>
     *
     * @param userGroups 用户分组逗号拼接字符串
     * @return 获取用户id分组
     * @Author Zhu.yj
     * @createDate  2021/4/9
     */
    @Override
    @PostMapping("property/householdRole/checkUserGroupExist")
    public List<String> checkUserGroupExist(@RequestParam("userGroups") String userGroups, @RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.checkUserGroupExist(userGroups, projectId);
    }

    /**
     * <desc>
     *      删除用户权限
     * </desc>
     *
     * @param userId 用户id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/13
     */
    @Override
    @PostMapping("/property/householdRole/deleteUserDeviceAuth")
    public Integer deleteUserDeviceAuth(@RequestParam("userId") String userId,@RequestParam("projectId") String projectId) throws Exception {
        return iPropertyHouseholdRoleService.deleteUserDeviceAuth(userId, projectId);
    }

    /**
     * <desc>
     *      用户角色组授权
     * </desc>
     *
     * @param propertyHouseholdRoleAuthDTO 用户及角色组传参
     * @return
     * @Author Zhu.yj
     * @createDate  2021/4/22
     */
    @Override
    @PostMapping("/property/setting/user/userRoleGroupAuth")
    public Integer userRoleGroupAuth(@RequestBody PropertyHouseholdRoleAuthDTO propertyHouseholdRoleAuthDTO) throws Exception {
        return iPropertyHouseholdRoleService.userRoleGroupAuth(propertyHouseholdRoleAuthDTO);
    }

    /**
     * <desc>
     *      获取指定电梯所绑定群控器下的所有电梯
     * </desc>
     *
     * @param deviceUnique 电梯唯一编码
     * @return 电梯机号
     * @Author Juguang.S
     * @createDate  2021/5/10
     */
    @Override
    @PostMapping(path = "property/householdRole/getCloudControllerElevatorInfo")
    public List<String> getCloudControllerElevatorInfo(@RequestParam("deviceUnique") String deviceUnique) throws Exception{
        return iPropertyHouseholdRoleService.getCloudControllerElevatorInfo(deviceUnique);
    }

    /**
     * <desc>
     *      获取同一群控器下绑定的电梯
     * </desc>
     *
     * @param currentDeviceUniques 当前也所有设备唯一码
     * @return
     * @Author Zhu.yj
     * @createDate  2021/5/17
     */
    @PostMapping("property/householdRole/getDeviceUniqueIdList")
    public String getDeviceUniqueIdList(@RequestParam("currentDeviceUnique") String currentDeviceUniques, @RequestParam("projectId") String projectId) throws Exception{
        return iPropertyHouseholdRoleService.getDeviceUniqueIdList(currentDeviceUniques, projectId);
    }

}
